﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using tms.Roles.Dto;
using Microsoft.AspNetCore.Mvc;
using tms.Filters;
using tms.Admins.Dto;

namespace tms.Roles
{
    [CustomerAuth]
    [ApiExplorerSettings(GroupName = "v1")]    
    public class RoleService : CrudAppService<Role, RoleDto, Guid, PagedAndSortedResultRequestDto, CreateUpdateRoleDto>, IRoleService
    {
        private readonly IRepository<Role, Guid> repository;

        public RoleService(IRepository<Role, Guid> repository) : base(repository)
        {
            this.repository = repository;
        }

        [HttpPost("/Role/Create")]
        public async Task<ResultDto<RoleDto>> CreateRoleAsync(CreateUpdateRoleDto input)
        {
            var Exists = await repository.AnyAsync(m => m.RoleName == input.RoleName);
            if (Exists)
            {
                return new ResultDto<RoleDto> { Code = ResultState.Failed, Msg = "用户已存在" };
            }
            await base.CreateAsync(input);
            return new ResultDto<RoleDto> { Code = ResultState.Success };
        }

        public override Task<RoleDto> GetAsync(Guid id)
        {
            return base.GetAsync(id);
        }

        public override Task<PagedResultDto<RoleDto>> GetListAsync(PagedAndSortedResultRequestDto input)
        {
            return base.GetListAsync(input);
        }
    }
}